package com.zhanghu.backendZray.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhanghu.backendZray.pojo.entity.UserRole;
import com.zhanghu.backendZray.mapper.UserRoleMapper;
import com.zhanghu.backendZray.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangdong
 * @since 2024-07-20
 */
@Service
@RequiredArgsConstructor
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    /**
     * 获取用户的角色id集合
     * @param userId
     * @return
     */
    public List<Integer> getRoleIdListByUserId(Integer userId) {
        List<UserRole> list = baseMapper.selectList(new LambdaQueryWrapper<>(UserRole.class).eq(UserRole::getUserId, userId));
        return list.stream().map(r -> r.getRoleId()).distinct().collect(Collectors.toList());
    }

}
